package org.hive.hive;

import java.io.InputStream;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;

public class fullimages extends Activity implements OnClickListener{
	Button showmap;
	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fullimages);
        showmap=(Button)findViewById(R.id.showmap);
        showmap.setOnClickListener(this);
        if (Global.is_reco_photo_selected)
        {
        	int tempPhotoid = (Integer)Global.imgviewtoidmapping.get(Global.selected_photo_id);
        	photos selectedphoto = (photos)Global.recoPhotos.get(tempPhotoid);
        	try{
        		int userid = selectedphoto.owner_id;
        		int albumid = selectedphoto.albumid;
        		Global.sel_pho_lat = selectedphoto.lat;
        		Global.sel_pho_lng = selectedphoto.lon;
        		
        		HttpClient hc = new DefaultHttpClient();
				HttpPost post = new HttpPost(Global.URL+"MobilePhotoDownload?userid="+userid+"&albumid="+albumid+"&photoid="+tempPhotoid+"&isthumb=no");

				HttpResponse rp = hc.execute(post);

				InputStream in = rp.getEntity().getContent();

				Bitmap bitmap = BitmapFactory.decodeStream(in);
				int width =bitmap.getWidth();
				System.out.println(width);
				in.close();
				
				ImageView img = (ImageView) findViewById(R.id.fullimage);
				img.setImageBitmap(bitmap);
        	}
        	catch(Exception e)
        	{
        		e.printStackTrace();
        	}
        }
        else
        {
        	int tempPhotoid = (Integer)Global.imgviewtoidmapping.get(Global.selected_photo_id);
        	photos selectedphoto = (photos)Global.takenPhotos.get(tempPhotoid);
        	try{
        		int userid = selectedphoto.owner_id;
        		int albumid = selectedphoto.albumid;
        		Global.sel_pho_lat = selectedphoto.lat;
        		Global.sel_pho_lng = selectedphoto.lon;
        		
        		HttpClient hc = new DefaultHttpClient();
				HttpPost post = new HttpPost(Global.URL+"MobilePhotoDownload?userid="+userid+"&albumid="+albumid+"&photoid="+tempPhotoid+"&isthumb=no");

				HttpResponse rp = hc.execute(post);

				InputStream in = rp.getEntity().getContent();

				Bitmap bitmap = BitmapFactory.decodeStream(in);
				int width =bitmap.getWidth();
				System.out.println(width);
				in.close();
				
				ImageView img = (ImageView) findViewById(R.id.fullimage);
				img.setImageBitmap(bitmap);
        	}
        	catch(Exception e)
        	{
        		e.printStackTrace();
        	}
        }
}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		Intent i;
		i=new Intent(this,map.class);
		startActivity(i);
	}
}
